<template>
  <a-modal class="enterprise_modal" v-model="visible" :title="title" :confirmLoading="submitLoading" width="1200px"
    ok-text="确认" cancel-text="取消" @ok="addFormSubmit">
    <a-form layout="inline" :form="events_form">
      <a-page-header title="登录账号信息" v-if="type == 0">
        <a-form-item label="客户账号">
          <a-input v-decorator="['loginAccount', { rules: [{ required: true, message: '请输入客户账号' }] }]" />
        </a-form-item>
        <a-form-item label="客户密码">
          <a-input v-decorator="['password', { rules: [{ required: true, message: '请输入客户密码' }] }]" />
        </a-form-item>
      </a-page-header>
      <a-page-header title="基础信息" v-if="type == 0 || type == 1">
        <a-form-item label="客户名称">
          <a-input
            v-decorator="['name', { rules: [{ required: true, message: '请输入客户名称' }, { min: 5, message: '长度不少于 5 个字符' }] }]" />
        </a-form-item>
        <a-form-item label="联系人名称">
          <a-input v-decorator="['contactName', { rules: [{ required: true, message: '请输入联系人名称' }] }]" />
        </a-form-item>
        <!-- <a-form-item label="客户经理">
          <a-tree-select v-decorator="['customerManagerId', { rules: [{ required: true, message: '请选择客户经理' }] }]"
            :tree-data="orgList" :replace-fields="{ key: 'key', value: 'value', title: 'title' }" placeholder="选择客户经理" />
        </a-form-item> -->
        <a-form-item label="联系人电话">
          <a-input v-decorator="['contactPhone', { rules: [{ required: true, message: '请输入联系人电话' }] }]" />
        </a-form-item>
        <!-- <a-form-item label="财务负责">
          <a-tree-select v-decorator="['financialManagerId', { rules: [{ required: true, message: '请选择财务负责' }] }]"
            :tree-data="orgList" :replace-fields="{ key: 'key', value: 'value', title: 'title' }" placeholder="选择财务负责" />
        </a-form-item> -->
        <a-form-item label="所属行业">
          <a-input v-decorator="['industry', { rules: [{ required: true, message: '请输入所属行业' }] }]" />
        </a-form-item>
        <a-form-item label="法人姓名">
          <a-input v-decorator="['legalPersonName', { rules: [{ required: true, message: '请输入法人姓名' }] }]" />
        </a-form-item>
        <!-- <a-form-item label="法人身份证号">
          <a-input v-decorator="['legalPersonIdCard', { rules: [{ required: true, message: '请输入法人身份证号' }] }]" />
        </a-form-item> -->
        <a-form-item label="统一信用代码">
          <a-input v-decorator="['creditCode', { rules: [{ required: true, message: '请输入统一信用代码' }] }]" />
        </a-form-item>
        <a-form-item label="企业地址">
          <a-input v-decorator="['address', { rules: [{ required: true, message: '请输入企业地址' }] }]" />
        </a-form-item>
        <a-form-item label="银行账户">
          <a-input v-decorator="['bankAccountName', { rules: [{ required: true, message: '请输入银行账户' }] }]" />
        </a-form-item>
        <a-form-item label="银行账号(开票)">
          <a-input v-decorator="['bankAccount', { rules: [{ required: true, message: '银行账号(开票)' }] }]" />
        </a-form-item>
        <a-form-item label="开户行(开票)">
          <a-input v-decorator="['bankNo', { rules: [{ required: true, message: '请输入开户行(开票)' }] }]" />
        </a-form-item>
        <a-form-item label="客户角色">
          <a-select @focus="roleChange()" v-decorator="['roleId', { rules: [{ required: true, message: '请选择角色!' }] }]">
            <a-select-option v-for="role in roleData" :key="role.roleId">
              {{ role.roleName }}
            </a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="归属服务公司">
          <a-tree-select v-decorator="['associateParkIds', { rules: [{ required: true, message: '请选择归属服务公司' }] }]"
            :tree-data="companyList" :replace-fields="{ key: 'key', value: 'value', title: 'title' }"
            placeholder="选择归属服务公司" tree-checkable />
        </a-form-item>
        <a-form-item label="发票类型">
          <a-select v-decorator="['billType', { rules: [{ required: true, message: '请选择发票类型!' }] }]">
            <a-select-option :key="1">
              一般纳税人/6%
            </a-select-option>
            <a-select-option :key="3">
              小规模企业/5%
            </a-select-option>
            <a-select-option :key="2">
              小微企业/1%
            </a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="服务城市">
          <a-select v-decorator="['city', { rules: [{ required: true, message: '请选择服务城市' }] }]" placeholder="请选择服务城市" show-search :filter-option="filterOption">
            <a-select-option :key="item" v-for="item in city">{{ item }}</a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="是否有残疾人业务">
          <a-select v-decorator="['disabledBusiness']" placeholder="请选择残疾人业务">
            <a-select-option :key="1">
              有
            </a-select-option>
            <a-select-option :key="0">
              没有
            </a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item label="合同协议" style="width: 100%;">
          <div>
            <a-button @click="contractTep()" type="primary">点击上传合同</a-button>
            <input type="file" ref="contractFile" @change="(e) => { return contractFileHandle(e) }"
              style="display: none;" />
          </div>
          <div v-for="item, index in modifyForm.contract" :key="item.id"
            style="display: flex;justify-content: space-between;align-items: center;margin-bottom: 10px;">
            <a :href="item" target="_blank" style="line-height: 1.5;">{{ strSlice(item) }}</a>
            <a @click="delContract(index)" style="flex-shrink: 0;">删除</a>
          </div>
        </a-form-item>
        <a-form-item label="是否有落地服务商">
          <a-select v-model="isFall">
            <a-select-option key="1">
              是
            </a-select-option>
            <a-select-option key="0">
              否
            </a-select-option>
          </a-select>
        </a-form-item>
        <div v-if="isFall == 1">
          <a-form-item label="落地服务商">
            <a-select v-model="localServiceIds" placeholder="请选择落地服务商" mode="multiple">
              <a-select-option v-for="item in fallList" :key="item.localServiceId">
                {{ item.localServiceName }}
              </a-select-option>
            </a-select>
          </a-form-item>
        </div>
        <a-form-item label="是否有渠道">
          <a-select v-model="isDitch">
            <a-select-option key="1">
              是
            </a-select-option>
            <a-select-option key="0">
              否
            </a-select-option>
          </a-select>
        </a-form-item>
        <div v-if="isDitch == 1">
          <a-form-item label="渠道名称">
            <a-select v-model="channelId" @change="channelChange" placeholder="选择渠道名称">
              <a-select-option v-for="item in channelList" :key="item.channelId">
                {{ item.channelName }}
              </a-select-option>
            </a-select>
          </a-form-item>
          <a-form-item label="渠道联系人">
            <a-input v-model="concatName" />
          </a-form-item>
          <a-form-item label="渠道联系电话">
            <a-input v-model="concatPhone" />
          </a-form-item>
        </div>
      </a-page-header>
      <a-page-header title="附加信息" v-if="type == 0 || type == 1">
        <a-row :gutter="20">
          <a-col :span="12">
            <a-form-item label="营业执照" labelAlign="left">
              <div v-show="modifyForm.businessLicense">
                <img :src="modifyForm.businessLicense" style="width:180px;height:120px;" />
                <div class="businessLicense" v-show="false" v-viewer="{ movable: false }">
                  <img :src="modifyForm.businessLicense" style="width:180px;height:120px;" />
                </div>
                <div style="padding:5px;display:flex">
                  <a href="#" style="padding-right:55px" @click="showDo('businessLicense')">查看大图</a>
                  <a href="#" type="link" @click="uploadImg(1)">重新上传</a>
                </div>
              </div>
              <div v-show="!modifyForm.businessLicense">
                <a head="#" @click="uploadImg(1)">上传营业执照</a>
                <input type="file" ref="businessLicense" @change="(e) => { return handleChange(e, 1) }"
                  style="display: none;" />
              </div>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="其他资质" labelAlign="left">
              <div v-show="modifyForm.naturalEndowments">
                <img :src="modifyForm.naturalEndowments" style="width:180px;height:120px;" />
                <div class="naturalEndowments" v-show="false" v-viewer="{ movable: false }">
                  <img :src="modifyForm.naturalEndowments" style="width:180px;height:120px;" />
                </div>
                <div style="padding:5px;display:flex">
                  <a href="#" style="padding-right:55px" @click="showDo('naturalEndowments')">查看大图</a>
                  <a href="#" type="link" @click="uploadImg(2)">重新上传</a>
                </div>
              </div>
              <div v-show="!modifyForm.naturalEndowments">
                <a head="#" @click="uploadImg(2)">上传其他资质</a>
                <input type="file" ref="naturalEndowments" @change="(e) => { return handleChange(e, 2) }"
                  style="display: none;" />
              </div>
            </a-form-item>
          </a-col>
          <!-- <a-col :span="8">
            <a-form-item label="法人身份证反面" labelAlign="left">
              <div v-show="modifyForm.legalPersonIdCardBack">
                <img :src="modifyForm.legalPersonIdCardBack" style="width:180px;height:120px;" />
                <div class="legalPersonIdCardBack" v-show="false" v-viewer="{ movable: false }">
                  <img :src="modifyForm.legalPersonIdCardBack" style="width:180px;height:120px;" />
                </div>
                <div style="padding:5px;display:flex">
                  <a href="#" style="padding-right:55px" @click="showDo('legalPersonIdCardBack')">查看大图</a>
                  <a href="#" type="link" @click="uploadImg(3)">重新上传</a>
                </div>
              </div>
              <div v-show="!modifyForm.legalPersonIdCardBack">
                <a head="#" @click="uploadImg(3)">上传法人身份证反面</a>
                <input type="file" ref="legalPersonIdCardBack" @change="(e) => { return handleChange(e, 3) }"
                  style="display: none;" />
              </div>
            </a-form-item>
          </a-col> -->
        </a-row>
      </a-page-header>

      <a-page-header title="费用信息" v-if="type == 0 || type == 2" class="feeInfo">
        <a-form-item label="合作类型">
          <div class="cooperateType">
            <a-card v-for="item, itemIndex in feeSetList" :key="itemIndex" style="margin-bottom: 8px;">
              <div class="cardHead">
                <div style="flex-shrink: 0;">
                  <span>{{ item.bizTypeName }}</span>
                  -
                  <a-input placeholder="请输入业务类型标签" allowClear v-model="item.bizTypeTag" style="width: auto;"></a-input>
                </div>
                <a-icon type="delete" slot="extra" style="font-size: 18px;color: #ff4d4f;" @click="delType(itemIndex)" />
              </div>
              <div v-for="info, infoIndex in item.feeList" :key="infoIndex">
                <a-form-item :label="info.feeName">
                  <a-radio-group v-model="info.feeWay">
                    <a-radio :value="1">
                      按人数
                    </a-radio>
                    <a-radio :value="2">
                      按系数
                    </a-radio>
                  </a-radio-group>
                </a-form-item>
                <a-form-item :label="info.feeType | feeValueName">
                  <a-input style="width: 200px;margin-right: 5px;" v-model="info.feeValue" />
                  <span v-if="info.feeWay == 1">元</span>
                  <span v-else>%</span>
                </a-form-item>
              </div>
            </a-card>
          </div>
          <a-button type="primary" ghost size="large" block @click="bizTypeClick"
            style="margin: 0 auto;width: 50%;display: block;">
            <a-icon type="plus" />
          </a-button>
        </a-form-item>
      </a-page-header>
    </a-form>
    <a-modal v-model="bizTypeVisible" title="添加合作类型" @ok="addBizType">
      <a-select v-model="bizType" @change="bizTypeChange" style="width: 240px;">
        <a-select-option v-for="item in bizTypeList" :key="item.bizType" :name="item.bizTypeName">
          {{ item.bizTypeName }}
        </a-select-option>
      </a-select>
    </a-modal>
  </a-modal>
</template>

<script>
import md5 from 'md5'
import store from '@/store'
import {
  uploadNewFile,
  sysListBaseInfo
} from '@/api/manage/base'
import {
  TAX_DATA
} from '@/store/mutation-types'
import {
  mapGetters,
  mapActions
} from 'vuex'
import {
  getEnterpriseInfo,
  addEnterprise,
  editEnterprise,
  enterpriseFeeInfo,
  costEnterprise,
  listEnterpriseBizType
} from "@/api/human/enterprise"
import {
  getAllOrgList
} from "@/api/human/department"
import {
  listChannel,
  getChannelInfo,
  getFallList
} from "@/api/human/canal"
export default {
  name: 'AddInfo',
  filters: {
    feeValueName(value) {
      let text = "";
      if (value == 1) {
        text = "薪酬服务费每人收取"
      } else if (value == 2) {
        text = "社保服务费每人收取"
      } else if (value == 3) {
        text = "服务费每人收取"
      } else if (value == 4) {
        text = "服务费支付每人"
      } else if (value == 5) {
        text = "服务费支付每人"
      }
      return text;
    }
  },
  data() {
    return {
      taxData: TAX_DATA,
      visible: false,
      logo: '',
      title: '',
      type: 0, // 0-新增 1-编辑 2-费用设置
      id: '',
      enterpriseId: '',
      submitLoading: false,

      modifyForm: {
        businessLicense: "",
        naturalEndowments: "",
        legalPersonIdCardBack: "",
        contract: [],
      }, // 上传的附件信息
      accountType: "",
      roleData: [], // 角色列表
      orgList: [], // 所有部门人员
      companyList: [], // 归属服务公司
      feeSetList: [], // 合作类型费用设置

      isFall: "0", // 落地服务商开关
      fallList: [], // 落地服务商信息
      localServiceIds: [], // 落地服务商id

      disabledBusiness: "", // 残疾人业务
      isDitch: "0", // 渠道开关
      channelList: [], // 渠道信息
      channelId: "", // 渠道id
      concatName: "", // 渠道联系人
      concatPhone: "", // 渠道联系电话

      bizTypeVisible: false, // 合作类型开关
      bizType: 1, // 合作类型
      bizTypeName: "人才派遣", // 合作类型名称
      bizTypeList: [], // 企业业务数据字典

      city: ["北京市", "上海市", "重庆市", "天津市", "石家庄市", "唐山市", "秦皇岛市", "邯郸市", "邢台市", "保定市", "张家口市", "承德市", "沧州市", "廊坊市", "衡水市", "太原市", "大同市", "阳泉市", "长治市", "晋城市", "朔州市", "忻州市", "吕梁市", "晋中市", "临汾市", "运城市", "呼和浩特市", "包头市", "乌海市", "赤峰市", "呼伦贝尔市", "通辽市", "乌兰察布市", "鄂尔多斯市", "巴彦淖尔市", "沈阳市", "大连市", "鞍山市", "抚顺市", "本溪市", "丹东市", "锦州市", "营口市", "阜新市", "辽阳市", "盘锦市", "铁岭市", "朝阳市", "葫芦岛市", "长春市", "吉林市", "四平市", "辽源市", "通化市", "白山市", "白城市", "松原市", "哈尔滨市", "齐齐哈尔市", "牡丹江市", "佳木斯市", "大庆市", "伊春市", "鸡西市", "鹤岗市", "双鸭山市", "七台河市", "绥化市", "黑河市", "南京市", "无锡市", "徐州市", "常州市", "苏州市", "南通市", "连云港市", "淮安市", "盐城市", "扬州市", "镇江市", "泰州市", "宿迁市", "杭州市", "宁波市", "温州市", "绍兴市", "湖州市", "嘉兴市", "金华市", "衢州市", "台州市", "丽水市", "舟山市", "合肥市", "芜湖市", "蚌埠市", "淮南市", "马鞍山市", "淮北市", "铜陵市", "安庆市", "黄山市", "阜阳市", "宿州市", "滁州市", "六安市", "宣城市", "池州市", "亳州市", "福州市", "厦门市", "莆田市", "三明市", "泉州市", "漳州市", "南平市", "龙岩市", "宁德市", "南昌市", "赣州市", "宜春市", "吉安市", "上饶市", "抚州市", "九江市", "景德镇市", "萍乡市", "新余市", "鹰潭市", "济南市", "青岛市", "淄博市", "枣庄市", "东营市", "烟台市", "潍坊市", "济宁市", "泰安市", "威海市", "日照市", "滨州市", "德州市", "聊城市", "临沂市", "菏泽市", "郑州市", "开封市", "洛阳市", "平顶山市", "安阳市", "鹤壁市", "新乡市", "焦作市", "濮阳市", "许昌市", "漯河市", "三门峡市", "商丘市", "周口市", "驻马店市", "南阳市", "信阳市", "武汉市", "黄石市", "十堰市", "荆州市", "宜昌市", "襄阳市", "鄂州市", "荆门市", "黄冈市", "孝感市", "咸宁市", "随州市", "长沙市", "株洲市", "湘潭市", "衡阳市", "邵阳市", "岳阳市", "张家界市", "益阳市", "常德市", "娄底市", "郴州市", "永州市", "怀化市", "广州市", "深圳市", "珠海市", "汕头市", "佛山市", "韶关市", "湛江市", "肇庆市", "江门市", "茂名市", "惠州市", "梅州市", "汕尾市", "河源市", "阳江市", "清远市", "东莞市", "中山市", "潮州市", "揭阳市", "云浮市", "南宁市", "柳州市", "桂林市", "梧州市", "北海市", "崇左市", "来宾市", "贺州市", "玉林市", "百色市", "河池市", "钦州市", "防城港市", "贵港市", "海口市", "三亚市", "三沙市", "儋州市", "成都市", "绵阳市", "自贡市", "攀枝花市", "泸州市", "德阳市", "广元市", "遂宁市", "内江市", "乐山市", "资阳市", "宜宾市", "南充市", "达州市", "雅安市", "广安市", "眉山市", "巴中市", "贵阳市", "六盘水市", "遵义市", "安顺市", "毕节市", "铜仁市", "昆明市", "曲靖市", "玉溪市", "保山市", "昭通市", "丽江市", "普洱市", "临沧市", "拉萨市", "日喀则市", "昌都市", "林芝市", "山南市", "那曲市", "西安市", "铜川市", "宝鸡市", "咸阳市", "渭南市", "延安市", "汉中市", "榆林市", "安康市", "商洛市", "兰州市", "嘉峪关市", "金昌市", "白银市", "天水市", "武威市", "张掖市", "平凉市", "酒泉市", "庆阳市", "定西市", "陇南市", "西宁市", "海东市", "银川市", "石嘴山市", "吴忠市", "固原市", "中卫市", "乌鲁木齐市", "克拉玛依市", "吐鲁番市", "哈密市"]
    }
  },
  beforeCreate() {
    this.events_form = this.$form.createForm(this, {
      name: 'events_form'
    });
  },
  computed: {

  },
  methods: {
    ...mapActions({
      getAllDepartmentRole: 'department/getAllDepartmentRole'
    }),
    // 打开编辑弹窗
    async add(rows, type) {
      this.title = type === 0 ? '新增客户' : type === 1 ? '编辑客户' : '费用设置';
      this.id = rows === true ? '' : rows.id;
      this.type = type;
      this.visible = true;
      this.feeSetList = [];
      // this.getOrgList();
      if (type !== 2) {
        // 费用设置不调用接口
        this.getSysListBaseInfo();
        this.getListChannel();
        this.getListFall();
      }
      this.getBizTypeList();
      // this.roleData = await store.dispatch('department/getAllDepartmentRole', '1JX2GQKRMKOYMHFK4HSZQDM5FN917Y');
      this.isDitch = '0';
      this.channelId = "";
      this.isFall = '0';
      this.localServiceIds = [];
      if (rows === true) {
        // 新增
        this.modifyForm.contract = [];
        this.modifyForm.businessLicense = '';
        this.modifyForm.naturalEndowments = '';
        this.$nextTick(() => {
          this.events_form.resetFields();
        })
      } else {
        // 修改
        this.id = rows.id;
        this.enterpriseId = rows.enterpriseId;
        if (this.type == 2) {
          let { code, data } = await enterpriseFeeInfo(rows.enterpriseId)
          if (code == '1') {
            this.feeSetList = data
          }
        } else {
          let { code, data } = await getEnterpriseInfo({ enterpriseId: rows.enterpriseId })
          let values = this.events_form.getFieldsValue();
          if (code == '1') {
            for (var key in data) {
              if (key == 'associateParkIds') {
                values[key] = data[key].split(',')
              } else {
                values[key] = data[key]
              }
            }
            this.roleData.push({
              roleName: data.roleName,
              roleId: data.roleId
            })
            // 处理渠道id
            if (data.channelId) {
              this.isDitch = '1';
              this.channelId = data.channelId;
              this.channelInfo(data.channelId);
            } else {
              this.isDitch = '0';
              this.concatName = "";
              this.concatPhone = "";
            }
            // 处理落地服务商id
            if (data.localServiceIds) {
              this.isFall = '1';
              this.localServiceIds = data.localServiceIds.split(",");
            } else {
              this.isFall = '0';
              this.localServiceIds = [];
            }
            if (data.contract) {
              this.modifyForm.contract = data.contract.split(',');
            } else {
              this.modifyForm.contract = [];
            }
            
            this.modifyForm.businessLicense = data.businessLicense;
            this.modifyForm.naturalEndowments = data.naturalEndowments;
            this.events_form.setFieldsValue(values);
          }
        }
      }
    },
    // 打开合作类型
    bizTypeClick() {
      this.bizTypeVisible = true;
    },
    // 选择合作类型
    bizTypeChange(value, option) {
      this.bizType = value;
      this.bizTypeName = option.data.attrs.name;
    },
    // 选择客户角色
    async roleChange() {
      this.roleData = await store.dispatch('department/getAllDepartmentRole', '1JX2GQKRMKOYMHFK4HSZQDM5FN917Y');
    },
    // 获取部门所有人员
    async getOrgList() {
      const {
        code,
        data
      } = await getAllOrgList();
      if (code === '1') {
        let array = [];
        data.forEach(m => {
          let paterObj = {
            key: m.orgId,
            value: m.orgId,
            title: m.orgName,
            selectable: false,
            children: []
          }
          m.staffs.forEach(item => {
            let childObj = {
              key: item.staffId,
              value: item.staffId,
              title: item.name
            }
            paterObj.children.push(childObj)
          })
          array.push(paterObj)
        })
        this.orgList = array;
      }
    },
    // 获取所有平台基础信息
    async getSysListBaseInfo() {
      const {
        code,
        data
      } = await sysListBaseInfo();
      if (code == "1") {
        let array = [];
        data.forEach(m => {
          let paterObj = {
            key: m.parkId,
            value: m.parkId,
            title: m.name,
          }
          array.push(paterObj)
        })
        this.companyList = array;
      }
    },
    // 获取所有合作类型信息
    async getBizTypeList() {
      const {
        code,
        data
      } = await listEnterpriseBizType();
      if (code == "1") {
        this.bizTypeList = data;
      }
    },
    // 获取所有落地服务商信息
    async getListFall() {
      const {
        code,
        data
      } = await getFallList();
      if (code == "1") {
        this.fallList = data;
      }
    },
    // 获取所有渠道信息
    async getListChannel() {
      const {
        code,
        data
      } = await listChannel();
      if (code == "1") {
        this.channelList = data;
      }
    },
    channelChange(value) {
      this.channelInfo(value);
    },
    // 获取渠道详情信息
    async channelInfo(id) {
      const {
        code,
        data
      } = await getChannelInfo(id);
      if (code == "1") {
        this.concatName = data.concatUserName;
        this.concatPhone = data.concatPhone
      }
    },
    // 合作协议名称截取
    strSlice(str) {
      const spliceLength = str.lastIndexOf("/");
      return str.slice(spliceLength + 1);
    },
    // 查看大图
    showDo(el) {
      const viewer = this.$el.querySelector('.' + el).$viewer
      viewer.show()
    },
    // 上传合同
    contractTep() {
      this.$refs.contractFile.click();
    },
    async contractFileHandle(e) {
      e.preventDefault();
      let _this = this;
      let file = e.target.files[0];
      if (file === undefined) {
        e.target.value = "";
        return;
      }
      var params = new FormData();
      params.append("file", file);
      params.append("dirName", '企业列表');
      let {
        code,
        data
      } = await uploadNewFile(params);
      if (code === '1') {
        this.modifyForm.contract.push(data);
      }
    },
    // 删除上传合同
    delContract(i) {
      this.modifyForm.contract.splice(i, 1)
    },
    // 上传图片
    uploadImg(type) {
      if (type === 1) {
        this.$refs.businessLicense.click()
      } else if (type === 2) {
        this.$refs.naturalEndowments.click()
      }
    },
    async handleChange(e, type) {
      e.preventDefault();
      let _this = this;
      let file = e.target.files[0];
      if (file === undefined) {
        e.target.value = "";
        return;
      }
      if (file.type.indexOf('image') === -1) {
        _this.$message.error("非法图片格式");
        e.target.value = "";
        return;
      }
      var params = new FormData();
      params.append("file", file);
      params.append("dirName", '企业列表');
      let {
        code,
        data
      } = await uploadNewFile(params);
      if (code === '1') {
        if (type === 1) {
          this.modifyForm.businessLicense = data;
        } else if (type === 2) {
          this.modifyForm.naturalEndowments = data;
        }
        e.target.value = "";
      }
    },
    // 添加合作类型
    addBizType() {
      // let isBool = false;
      // this.feeSetList.forEach(item => {
      //   if ((this.bizType) == item.bizType) {
      //     isBool = true
      //   }
      // })
      // if (isBool) {
      //   return this.$message.warning('请不要重复添加合作类型和标签')
      // } else {}
      this.bizTypeVisible = false;
      this.feeSetList.push({
        bizType: this.bizType,
        bizTypeName: this.bizTypeName,
        bizTypeTag: '',
        feeList: [{
          feeType: '1',
          feeName: '薪酬服务费收取方式',
          feeWay: 1,
          feeValue: 0,
        }, {
          feeType: '2',
          feeName: '社保服务费收取方式',
          feeWay: 1,
          feeValue: 0,
        }, {
          feeType: '3',
          feeName: '渠道费用收取方式',
          feeWay: 1,
          feeValue: 0,
        }, {
          feeType: '4',
          feeName: '渠道费用支付方式',
          feeWay: 1,
          feeValue: 0,
        }, {
          feeType: '5',
          feeName: '落地服务商支付方式',
          feeWay: 1,
          feeValue: 0,
        }]
      })
    },
    // 删除合同类型
    delType(i) {
      this.feeSetList.splice(i, 1)
    },
    // 提交
    addFormSubmit() {
      const that = this;
      this.events_form.validateFieldsAndScroll(async (err, values) => {
        if (!err) {
          if (this.id) {
            values.id = this.id;
            values.enterpriseId = this.enterpriseId;
          }
          if (this.type == 0) {
            values.password = md5(values.password)
          }
          // 新增修改判断字段
          if (this.type == 0 || this.type == 1) {
            // if (!this.modifyForm.contract) {
            //   this.$message.error('请上传合同');
            //   return;
            // }
            // if (!this.modifyForm.businessLicense) {
            //   this.$message.error('请上传营业执照');
            //   return;
            // }
            values.businessLicense = this.modifyForm.businessLicense;
            values.naturalEndowments = this.modifyForm.naturalEndowments;
            values.associateParkIds = values.associateParkIds.join(',');
            values.contract = this.modifyForm.contract.join(',');
            values.roleName = this.roleData.find(v => v.roleId == values.roleId).roleName;
            if (this.isDitch == 1) {
              values.channelId = this.channelId;
            }
            if (this.isFall == 1) {
              values.localServiceIds = this.localServiceIds.join(',');
            }
          }
          // 费用设置判断字段
          if (this.type == 0 || this.type == 2) {
            let isMust = false;
            if (this.feeSetList.length > 0) {
              this.feeSetList.forEach((feeSet, i) => {
                if (feeSet.bizTypeTag == "") {
                  that.$message.warning("请添加合作类型标签");
                  isMust = true
                }
                // feeSet.feeList.forEach(fee => {
                //   if (fee.feeType == 1 && fee.feeValue == "") {
                //     this.$message.warning(feeSet.bizTypeName + ' - ' + feeSet.bizTypeTag + ': 薪酬服务费不能为空');
                //     isMust = true
                //   } else if (fee.feeType == 2 && fee.feeValue == "") {
                //     this.$message.warning(feeSet.bizTypeName + ' - ' + feeSet.bizTypeTag + ': 社保服务费不能为空');
                //     isMust = true
                //   }
                // })
              })
            } else {
              return that.$message.warning("请添加合作类型");
            }
            if (!isMust) {
              values.feeSetList = this.feeSetList;
            } else {
              return true
            }
            if (this.isRepeatBizeType()) {
              return
            }
          }
          that.submitLoading = true;
          // console.log(values);
          if (that.type == 2) {
            that.submitLoading = true;
            const {
              code
            } = await costEnterprise(values);
            that.submitLoading = false;
            if (code === '1') {
              that.visible = false;
              that.$message.success("操作成功");
              let state = that.id ? false : true;
              that.$emit('on-ok', state)
            }
          } else {
            const {
              code
            } = that.type == 0 ? await addEnterprise(values) : await editEnterprise(values);
            that.submitLoading = false;
            if (code === '1') {
              that.visible = false;
              that.$message.success("操作成功");
              let state = that.id ? false : true;
              that.$emit('on-ok', state)
            }
          }
        }
      });
    },
    // 判断费用设置合作类型是否重复
    isRepeatBizeType() {
      this.feeSetList.forEach(item=> {
        item.allType = item.bizTypeName + '-' + item.bizTypeTag
      })
      if (this.isRepeat(this.feeSetList,"allType")) {
        this.$message.warning("合作类型-标签不能重复");
        return true;
      } else {
        return false;
      }
    },
    // 数组中对象去重
    isRepeat(arr, type) {
      var hash = {};
      for (var i in arr) {
        if (hash[arr[i][type]]) {
          return true;
        } else {
          hash[arr[i][type]] = true;
        }
      }
      return false;
    },
    // 城市检索搜索
    filterOption(input, option) {
      return (
        option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
      );
    },
  }
}
</script>
<style lang="less">
.enterprise_modal {
  .ant-form-item {
    width: 50%;
    margin-right: 0;

    .ant-form-item-label {
      width: 165px;
    }

    .ant-form-item-control-wrapper {
      width: 385px;
    }
  }

  .cardHead {
    width: 100%;
    height: 56px;
    font-size: 16px;
    color: rgba(0, 0, 0, .85);
    font-weight: 500;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    border-bottom: 1px solid #e8e8e8;
    margin-top: -24px;
  }

  .feeInfo {
    .ant-form-item {
      width: 100%;

      .ant-form-item-control-wrapper {
        width: 935px;
      }
    }


    .cooperateType {
      .ant-form-item {
        width: 50%;

        .ant-form-item-label {
          width: 40%;
        }

        .ant-form-item-control-wrapper {
          width: 58%;
        }
      }

    }
  }

}
</style>
